import {baseEffects, baseReducers, baseState} from "../../../../models/baseModel";
import PageHelper from "utils/pageHelper";
import * as request from "../../../../services/CommonHttpService";
import AppService from "../../../../common/AppService";

export default {
  namespace: 'pushSetDevices',

  state: {
    ...baseState,
    DeviceType:[]
  },

  reducers: {
    ...baseReducers
  },

  effects: {

    ...baseEffects,

    // 进入页面加载
    * init({payload}, {put, call}) {
      const p = {
        ...payload,
        baseUrl: getBaseUrl(),
        server: AppService.dataUrl,
        process: (records) => {
          return records.map(data => {
            return {
              ...data,
              pushId:payload.page.id
            };
          });
        }
      };
      yield put({
        type: 'baseGetPageInfo',
        payload: p
      });
    },
    // 保存和修改
    * save({payload}, {put}) {

      yield put({
        type: 'baseSave',
        payload: {...payload, baseUrl: getBaseUrl(),server: AppService.dataUrl,}
      });
    },


    // 删除 之后查询分页
    * delete({payload}, {call, put, select}) {

      yield put({
        type: 'baseDelete',
        payload: {...payload, baseUrl: getBaseUrl(),server: AppService.dataUrl,}
      });
    },
    *getDeviceType({payload}, {call, put}) {
      let result = yield call(request.commonGet,'/device/type/', {},payload, AppService.dataUrl);
      const DeviceType = result.map(value => {
        return (
          {code: value.id, codeName: value.numeration}
        );
      });

      yield put({
        type: 'initState',
        payload: {DeviceType}
      });
    }
  }

}

function getBaseUrl() {
  return "/push/device";
}
